package user

import (
	"organoid_public/domain/sample"
	"organoid_public/domain/sample/repository"
	sampleService "organoid_public/domain/sample/service"
	"organoid_public/pkg/logger"
)

type service struct {
	log logger.Logger
	svc sampleService.UserServiceInterface
}

// 初始化应用层服务
func newService() (*service, error) {
	// 实例化领域服务
	domainSvc, err := sample.Service()
	if err != nil {
		return nil, err
	}
	return &service{svc: domainSvc.UserSvc}, nil

}

func (s *service) loginIn(params *LoginReq) (string, error) {
	data, err := s.svc.LoginIn(params.Username, params.Password)
	if err != nil {
		return "", err
	}
	return data, nil
}

func (s *service) headImgUpload(params *HeadImgUpReq) error {
	return s.svc.HeadImgUpload(&repository.HeadImgParams{
		Id:   params.Id,
		File: params.Files,
	})
}

func (s *service) CheckAuth(Token string) (*CheckAuthRep, error) {
	jwtTokenObj, err := s.svc.CheckAuth(Token)
	if err != nil {
		return nil, err
	}
	return &CheckAuthRep{
		Uid:            jwtTokenObj.Uid,
		Name:           jwtTokenObj.Name,
		StandardClaims: jwtTokenObj.StandardClaims,
	}, nil
}

func (s *service) LoginOut(tokenId string) (bool, error) {
	return s.svc.LoginOut(tokenId)
}
